package com.jovan.bio;

import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.net.Socket;

/**
 * @author: Jovan
 * @date: 2025/6/22
 * @description:
 */
public class BioClient {

    public static void main(String[] args) throws Exception {
        Thread tom = new Thread(()->{
            try {
                sendHello();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }, "tom");
        Thread jack = new Thread(()->{
            try {
                sendHello();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }, "jack");
        tom.start();
        jack.start();
        tom.join();
        jack.join();
    }
    public static void sendHello() throws Exception {
        Socket socket = new Socket();
        socket.connect(new InetSocketAddress("127.0.0.1", 8080));
        OutputStream outputStream = socket.getOutputStream();
        for (int i = 0; i < 10; i++) {
            outputStream.write((Thread.currentThread().getName() + " hello " + i).getBytes());
            outputStream.flush();
        }
        outputStream.close();
        System.out.println("客户端断开连接！");
    }
}
